import java.util.Scanner;
//二叉树的创建和遍历
public class Main {
    //创建TreeNode类
    static class TreeNode {
        private char val;
        private TreeNode left;
        private TreeNode right;
        public TreeNode(char val) {
            this.val = val;
        }
    }
    //根据字符串创建树
    public static int i = 0;
    public static TreeNode createTree(String str) {
        TreeNode root = null;
        char ch = str.charAt(i);
        if(ch!='#') {
            root = new TreeNode(ch);
            i++;
            root.left = createTree(str);
            root.right = createTree(str);
        } else {
            i++;
        }
        return root;
    }
    //中序遍历
    public static void midOrder(TreeNode root) {
        if(root==null) return;
        midOrder(root.left);
        System.out.print(root.val+" ");
        midOrder(root.right);
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            String str = in.nextLine();
            TreeNode root = createTree(str);
            midOrder(root);
        }
    }
}
